﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ARR.Entities;
using ARR.DataModel.Repositories;
using ARR.Shared;
using ARR.Entities.Validation;
using System.ServiceModel;

namespace ARR.Services.BizRules
{
    static class StoreBizRules
    {
        public static void ValidateDelete(Store store)
        {
            var storeSales = ArticleSalesRepository.Select(s => s.StoreId == store.Id);
            var storeRangeReviews = RangeReviewStoresRepository.Select(rrs => rrs.StoreId == store.Id);

            if (storeSales.Any())
                throw new FaultException(string.Format(Errors.CannotDeleteStoreBecauseRangeReviews, store.Code));

            if (storeRangeReviews.Any())
                throw new FaultException(string.Format(Errors.CannotDeleteStoreBecauseRangeReviews, store.Code));
        }

        public static void ValidateSave(Store store)
        {
            if (!store.IsValid)
                throw new FaultException(store.Error);            
        }
    }
}
